Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Patrik D 7 posts 47 karma points
    Apr 16, 2015 @ 18:09
    Patrik D
    0

    XSLT grouping stops to work when moved [Umbraco 4.7.0]

    Hello!

    I'm having some issues when I try to move a document type to a lower level than it is currently in, see figure below:

    In the new position, the XSLT-file does not output the same results as for the old position and I can't figure out why. The basic structure is

    <annonsarkiv level="3" ...>      (child of BTF Magazinet above)
        <annonsor level="4" ...>      (child of Annonsörer above)
            ...
            <foretagsomrade>Some text</foretagsomrade>
        </annonsor>
        <annonsor level="4" >
            ...
            <foretagsomrade>Some other text</foretagsomrade>
        </annonsor>
        ...

    and the page is suppose to group all "annonsor" by "foretagsomrade" and create something like

    Some text

     

    • Annonsor 1
    • Annonsor 2
    Some other text

     

    • Annonsor 3
    • Annonsor 4
    The XSLT, which works for the page in the old position, looks like this:
    <xsl:key name="omrade" match="*/annonsor" use="foretagsomrade" />
        
    <xsl:template match="/">
        

    <div id="accordion">
      <xsl:for-each select="$currentPage/annonsor [generate-id() = generate-id(key('omrade',foretagsomrade)[1])]">
        <xsl:sort select="foretagsomrade" order="ascending"/>
        <xsl:variable name="fomrade" select="foretagsomrade"/>
        <h3><href="#"><xsl:value-of select="$fomrade"/>a>h3>
        <div><div class="hr"> div><div class="archiveBtns">
          <ul>
          <xsl:for-each select="$currentPage/annonsor [foretagsomrade = $fomrade]">  
            <li><href="{umbraco.library:NiceUrl(@id)}">
              <xsl:value-of select="@nodeName"/>
              a>li>
          xsl:for-each>
          ul>
        div><div class="hr"> div>div>
      xsl:for-each>
    div>

    xsl:template>

    In my mind it looks good (although it probably can be done more efficiently?), as it says to first look up all unique names in "foretagsomrade" and create a list. Then for each unique value we select the "annonsor" which has this value in "foretagsomrade"

    Hope someone can shed some light on what might be wrong.

    Thanks in advance.

    Kind regards
    Patrik

     

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 16, 2015 @ 22:31
    Chriztian Steinmeier
    0

    Hi Patrik,

    You've just moved the Annonsörer node to a new location, right? But are you still executing the macro from the same page as before?

    The macro should work if run on the Annonsörer node - because the loops are specifically asking for child nodes of $currentPage, named <annonsor>.

    Otherwise we'll have to dig deeper... :)

    /Chriztian

  • Patrik D 7 posts 47 karma points
    Apr 17, 2015 @ 08:00
    Patrik D
    0

    Hi Chriztian,

    I've acturally made a copy of Annonsörer, since I did not know if it would work just by moving. Can this the source of the problem?

    Since I've made a copy, I can run the macro from both the old location and the new location - whereas it works in the old location but returns nothing in the new location.

    When I do <xsl:copy-of select="$currentPage" /> and compare the result printed on the old and the new location, the only difference is that in the old location I get

    <annonsarkiv level="2" ...>
        <umbracoNaviHide />
        <annonsor level="3" ...>
            ...
            <foretagsomrade>Some text</foretagsomrade>
            ...
        </annonsor>
        ...
    

    while in the new location I get

    <annonsarkiv level="3" ...>
        <annonsor level="4" ...>
            ...
            <foretagsomrade>Some text</foretagsomrade>
            ...
        </annonsor>
        ...
    

    So except for the levels being changed, in the old location there is also <umbracoNaviHide />, don't know why this one is not included in the other location - but it feels like the lack of this term should not result in hiding the results, right?

    I've tried to print the results from <xsl:key name="omrade" match="*/annonsor" use="foretagsomrade" /> using <xsl:copy-of select="omrade" /> but it returns empty on both pages - so I guess this is not the way to do it.

    If I do <xsl:copy-of select="$currentPage/annonsor/foretagsomrade" /> I get the same results on both pages, but then of course I do not get the unique list that I which to have, but one value of foretagsomrade per <annonsor>-node.

    Any ideas?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 17, 2015 @ 08:11
    Chriztian Steinmeier
    100

    Aha! :)

    Yes - that's the problem - the way grouping works is by (esentially) comparing the current node in the loop with the first node returned from the index created by the "keys stuff" - so in the new location, all the nodes are compared to the nodes from the original location (generate-id() will be unique for two nodes that are otherwise identical - even if they had the same @id).

    So yes - that's the problem. If you unpublish the original nodes it should start working...

    /Chriztian

  • Patrik D 7 posts 47 karma points
    Apr 17, 2015 @ 08:20
    Patrik D
    0

    Ah, ok. It worked :)

    Is it not possible to get it to work in some other way - would be nice to be able to work with the data in the new location if there is something else needing to be altered before unpublishing the old page?

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 17, 2015 @ 08:26
    Chriztian Steinmeier
    0

    Great,

    Yes, I guess you can scope the <xsl:key> to only index the newer nodes, e.g. by using the @level attribute:

    <xsl:key name="omrade" match="annonsor[@level &gt;= 4]" use="foretagsomrade" />
    

    Gotta love keys :-)

    /Chriztian

  • Patrik D 7 posts 47 karma points
    Apr 17, 2015 @ 09:03
    Patrik D
    0

    Thanks for the help Chriztian!

Please Sign in or register to post replies

Write your reply to:

Draft